package com.ipkiss.incomespringboot.mapper;

import com.ipkiss.incomespringboot.entity.FundEntity;
import com.ipkiss.incomespringboot.entity.OperateEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author WuYongheng
 * @date 2024/5/11
 * @describe
 */
public interface FundMapper {

    @Select("select * from fundDetails f order by f.operateTime desc")
    List<OperateEntity> getTableData();

    @Select("select * from funds")
    List<FundEntity> getFundsData();

    @Insert("insert into fundDetails " +
            "(fundCode , fundName , operateType , operateMoney , operateTime) " +
            "values " +
            "(#{fundCode} , #{fundName} , #{operateType}  ,#{operateMoney} , #{operateTime})")
    int createOperateInfo(OperateEntity operateEntity);

    @Update("update fundDetails " +
            "set " +
            "operateType = #{operateType} , " +
            "operateMoney = #{operateMoney} , " +
            "operateTime = #{operateTime} " +
            "where id = #{id}")
    int updateOperateInfo(OperateEntity operateEntity);

    @Delete("delete from fundDetails where id = #{id}")
    int deleteOperateInfo(int id);

    @Select("select f.* from fundDetails f" +
            " where (case when #{keyword} is not null then f.operateTime like binary concat('%',#{keyword},'%') else 1=1 end)" +
            " or (case when #{keyword} is not null then f.fundName like binary concat('%',#{keyword},'%') else 1=1 end)" +
            " or (case when #{keyword} is not null then f.operateType like binary concat('%',#{keyword},'%') else 1=1 end)" +
            " or (case when #{keyword} is not null then f.operateMoney like binary concat('%',#{keyword},'%') else 1=1 end)" +
            " order by f.id desc")
    List<OperateEntity> getFundListByKeyword(String keyword);

    @Select("select sum(f.operateMoney) from fundDetails f where f.operateType = '定投' ")
    Double getSumMoney();
}